package universum.util;

public class GameIterator {
    public int roundsCount = 0;
    private int curRoundNum = 0;
    private Statistics stats = Statistics.getInstance();
    public ExitConditionType exitCondition;
    public GameImitatorParams imitationParams;
    private static GameIterator _instance = new GameIterator();

    public enum ExitConditionType {
        roundNumber
    }

    private GameIterator() {
    }

    public static GameIterator getInstance() {return _instance;}

    public void Start() {
        CheckInitialData();
        Iterate();
        stats.PrepareReport();
        //stats.PublishForExcel();
        stats.PublishReport();
    }

    private void CheckInitialData() {
        boolean alright = true;
        if (exitCondition == null) alright = false;
        if (!alright) throw new IllegalArgumentException("inconsistent initial arguments.");
    }

    public int getRoundNumbert() {
        return curRoundNum;
    }
  
    private void Iterate() {

        while (toContinue()) {
            //stats.addReport("test", 0.4f, Statistics.AggregationType.avg);
            GameImitator imitator = new GameImitator();
            imitator.params = imitationParams;
            imitator.Imitate();
            stats.addReport("randtest", (float)Math.random(), Statistics.AggregationType.avg);                        
            stats.completedRoundsCount = ++curRoundNum;
        }
    }



    private boolean toContinue() {
        switch (exitCondition) {
            case roundNumber:
                return curRoundNum < roundsCount;
            default:
                throw new UnknownError("look outside, if there is a red snow? :)");//unreachable code
        }
    }
}

